import requests

from handlers.handler_log import logger
from handlers.handler_response import HandlerResponse


def contain_assertion(key, response: requests.Response, expected_data: int | str) -> bool:
    result = True
    try:
        actual_data = HandlerResponse().response_result_extract_nodes(response, key)
        assert actual_data in expected_data, f"'{key}' 的  预期结果: '{expected_data}' 不包含在  测试结果:'{actual_data}' 中！"
        logger.success(f"'{key}' 的测试结果: '{actual_data}' != 预期结果: '{expected_data}'，相等断言成功！")
    except AssertionError as e:
        logger.error(e)
        result = False
    finally:
        return result

